<!DOCTYPE html>
<html>
{include file="public/head"}
<body>
    {include file="public/nav"} {include file="problem/nav-2"}
<div class="layui-container">    
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md8">
                <div class="problem-content">
                    <ul style="text-align: center;">
                        <h1> {$problemitem.problem_id}-{$problemitem.title} </h1>
                    </ul>
                    <br/>
                    <ul style="text-align: center;">
                        <span class="layui-badge layui-bg-orange">内存限制:{$problemitem.memory_limit}MB</span>
                        <span class="layui-badge">时间限制:{$problemitem.time_limit*1000}ms</span>
                        <span class="layui-badge layui-bg-blue">特判: {eq name='problemitem.spj' value='0'}No{else/}Yes{/eq} </span>
                    </ul>
                    <ul style="text-align: center;">
                        <br/>
                        <span class="layui-badge layui-bg-green">通过数:{$problemitem.accepted}</span>
                        <span class="layui-badge layui-bg-gray">提交数:{$problemitem.submit}</span>
                        <span class="layui-badge layui-bg-orange">难度:{$problemitem.score}</span>
                    </ul>
                    <br/>
                    <br/>

                    <div class="fly-panel" style="margin-bottom: 0;">
                        <div class="nyoj-problem-content">
                            <h2 class="nyoj-problem-content-title">题目描述:</h2>
                            <div class="nyoj-problem-content-col nyoj-clear-width">
                                {$problemitem.description}
                            </div>
                        </div>
                    </div>
                    <div class="fly-panel" style="margin-bottom: 0;">
                        <div class="nyoj-problem-content">
                            <h2 class="nyoj-problem-content-title">输入描述:</h2>
                            <div class="nyoj-problem-content-col nyoj-clear-width">
                                <pre class='nyoj-pre-clear'>{:htmlspecialchars($problemitem.input)}</pre>
                            </div>
                        </div>
                    </div>
                    <div class="fly-panel" style="margin-bottom: 0;">
                        <div class="nyoj-problem-content">
                            <h2 class="nyoj-problem-content-title">输出描述:</h2>
                            <div class="nyoj-problem-content-col nyoj-clear-width">
                                <pre class='nyoj-pre-clear'>{:htmlspecialchars($problemitem.output)}</pre>
                            </div>
                        </div>
                    </div>
                    <div class="fly-panel" style="margin-bottom: 0;">
                        <div class="nyoj-problem-content" >
                            <h2 class="nyoj-problem-content-title">样例输入:</h2>
                            <div class="nyoj-problem-content-col nyoj-clear-width" style="padding: 10px;">
                                <button  class="cpoy-btn" onclick="copyToClipboard()" id="input-button">复制</button>
                                <pre id="input-box" lay-encode="true">{:htmlspecialchars($problemitem.sample_input)}</pre>
                            </div>
                        </div>
                    </div>
                    <div class="fly-panel" style="margin-bottom: 0;">
                        <div class="nyoj-problem-content" >
                            <h2 class="nyoj-problem-content-title">样例输出:</h2>
                            <div class="nyoj-problem-content-col nyoj-clear-width" style="padding: 10px;">
                                <pre lay-encode="true">{:htmlspecialchars($problemitem.sample_output)}</pre>
                            </div>
                        </div>
                    </div>
                    <div class="fly-panel" style="margin-bottom: 0;">
                        <div class="nyoj-problem-content">
                            <h2 class="nyoj-problem-content-title">提示:</h2>
                            <div class="nyoj-problem-content-col nyoj-clear-width">
                                {$problemitem.hint?$problemitem.hint:'没有提示哦'}
                            </div>
                        </div>
                    </div>
                    <div class="fly-panel" style="margin-bottom: 0;">
                        <div class="nyoj-problem-content">
                            <h2 class="nyoj-problem-content-title">来源:</h2>
                            <div class="nyoj-problem-content-col nyoj-clear-width">
                                <a href="{:url('web/problem/searchproblem',['source'=>$problemitem.source])}" class="fly-link">{$problemitem.source}</a>
                            </div>
                        </div>
                    </div>
                    
                    <div class="fly-panel" style="margin-bottom: 0;">
                        <div class="nyoj-problem-content">
                            <h2 class="nyoj-problem-content-title">上传者：<span style="color: blue;">{$problemitem.user_id}</span></h2>
                        </div>
                    </div>

                    <div class="" style="margin-bottom: 0;">
                        <ul class="submit-btn-comb">
                            <a class="layui-btn" id="submit-code" nyoj-cid="0" nyoj-pid="{$problemitem.problem_id}">代码提交</a>
                            <a class="layui-btn layui-btn-normal" href="{:url('web/Community/topicset','pid='.$problemitem.problem_id)}">查看讨论</a>
                            <a class="layui-btn layui-btn-normal" href="{:url('web/Community/addtopic','pid='.$problemitem.problem_id)}">发起提问</a>
                            {if condition="$have_power_0"}
                            <a class="layui-btn layui-btn-danger" target="_blank" href="{:url('admin/Problem/editor_opt',['id'=>$problemitem.problem_id,'flag'=>'1'])}">编辑问题</a>
                            {/if}
                        </ul>
                    </div>
                </div>
        </div>
         {include file="public/problem-side"}
    </div>
</div>
 {include file="public/foot"}
 </body>
<script>
    layui.use(['element', 'jquery', 'form', 'layer'], function() {
        // console.log('abcdef');
        var element = layui.element;
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        form.on('submit(delete)', function(data) {
            if (data.field.tag === undefined) {
                layer.msg('请先选中题目分类');
                return false;
            }
            $.ajax({
                url: "{:url('web/problem/tag_delete')}",
                type: 'post',
                data: data.field,
                dataType: "JSON",
                success: function(res) {
                    // console.log(res);
                    
                    if (res.result === 0) {
                        layer.msg(res.msg);
                        setTimeout("parent.location.reload()", 1000);
                    }
                    else {
                        layer.msg(res.msg);
                    }
                },
                error: function() {
                    layer.msg('进入后台失败~');
                }
            });
            return false;
        });
        form.on('submit(add)', function(data) {
            if (data.field.tag_level_1 === undefined || data.field.tag_level_1 < 0) {
                layer.msg('请先选择分类');
                return false;
            }
            // console.log(data.field);
            $.ajax({
                url: "{:url('web/problem/tag_add')}",
                type: 'post',
                data: data.field,
                dataType: "JSON",
                success: function(res) {
                    
                    if (res.result === 0) { 
                        // console.log("tag_id="+res.tag_id);
                        layer.msg(res.msg);
                        setTimeout("parent.location.reload()", 1000);
                    } else {
                        layer.msg(res.msg);
                    }
                },
                error: function() {
                    layer.msg('进入后台失败~');
                }
            });
            return false;
        });
        form.on('select(test1)', function(data) {
            // console.log(data.value);
            $.ajax({
                url: "{:url('web/problem/get_tag1_id')}",
                type: 'post', 
                data: { 'tid': data.value },
                dataType: "JSON",
                success: function(res) {
                    // layer.msg('获取数据成功');
                    // console.log(res);
                    $('#tag_level_2 option:gt(0)').remove();
                    $('#tag_level_3 option:gt(0)').remove();
                    $.each(res, function(i, item) {
                        $("<option value=" + item.tag_id + ">" + item.tag_name +
                            "</option>").appendTo($('#tag_level_2'));
                    });
                    form.render('select');
                },
                error: function() {
                    layer.msg('页面进入后台失败');
                }
            });
        });
        form.on('select(test2)', function(data) {
            // console.log(data.value);
            $.ajax({
                url: "{:url('web/problem/get_tag2_id')}",
                type: 'post',
                data: { 'tid': data.value },
                dataType: "JSON",
                success: function(res) {
                    // layer.msg('获取数据成功');
                    $('#tag_level_3 option:gt(0)').remove();
                    $.each(res, function(i, item) {
                        $("<option value=" + item.tag_id + ">" + item.tag_name +
                            "</option>").appendTo($('#tag_level_3'));
                    });
                    form.render('select');
                },
                error: function() {
                    layer.msg('页面进入后台失败');
                }
            });
        });
    });
    </script>
    {include file="public/submit-js"}
   <script>
    layui.use(['jquery','layer'],function(){
        var $=layui.jquery;
        var layer=layui.layer;
        var content = $("#input-box").text();  
            var clipboard = new ClipboardJS('#input-button', {  
            text: function() {  
            return content;  
        }  
    });  
    clipboard.on('success', function(e) {  
        layer.msg('复制成功');
    });  
  
    clipboard.on('error', function(e) {
                layer.msg('您的浏览器不支持复制哦~');
                console.log(e);
            });
    });
</script>
</html>